"use strict";
const Service = require("egg").Service;
var Sequelize = require('sequelize');
const crypto = require('crypto');
const { httpCode } = require("../../utils/userConfig")
const SystemErrException = require("../../exception/systemError");

class RoleService extends Service {

  async addRole(role) {
    try {
      const { ctx } = this;
      const result = await ctx.model.Sys.Role.create(role);
      return {
        data: result,
        code: httpCode.SUCCESS,
        message: "角色添加成功"
      }
    } catch (error) {
      throw new SystemErrException("角色添加异常：" + error);
    }
  }

  async getRoles() {
    try {
      const { ctx } = this;
      let roles = await ctx.model.Sys.Role.findAll({
        order: [['update_date', 'asc']], // 排序规则
      });
      return {
        data: roles,
        code: httpCode.SUCCESS,
        message: '角色查询成功！'
      }
    } catch (error) {
      throw new SystemErrException("角色查询异常：" + error);
    }
  }

}

module.exports = RoleService;
